const {
  getAdmMembers,
  getMemberInfo,
  postMember,
} = require("../service/ice/adm-member");
const { adm } = require("../service/ice/adm");

const { compareFace } = require("../service/third/face");
const { onOrderLogDone } = require("../service/ice/order-log");

const app = require("express").Router();

// 低权限内容，如banner
app.all("/auth/data/:type/:tab", async (req, res) => {
  const data = await adm.getData(req.params, req._body, req.user.sid);
  res.send(data);
});

// 成员
app.get("/auth/member-list", async (req, res) => {
  const data = await getAdmMembers(req.query, req.user);
  res.send(data);
});

app.get("/auth/member-info", async (req, res) => {
  const data = await getMemberInfo(req.query, req.user);
  res.send(data);
});

app.post("/auth/member-edit", async (req, res) => {
  const data = await postMember(req._body, req.user);
  res.send(data);
});

// 门店
app.get("/auth/shop-list", async (req, res) => {
  const data = await adm.getShopList(req.query);
  res.send(data);
});

app.get("/auth/shop-info", async (req, res) => {
  const data = await adm.getShopInfo(req.query);
  res.send(data);
});

app.post("/auth/shop-edit", async (req, res) => {
  const data = await adm.postShopEdit(req._body, req.user);
  res.send(data);
});

// 商品
app.get("/auth/goods-list", async (req, res) => {
  const data = await adm.getGoodsList(req.query, req.user.sid);
  res.send(data);
});

app.post("/auth/goods-edit", async (req, res) => {
  const data = await adm.postGoodsEdit(req._body, req.user.sid);
  res.send(data);
});

// 订单
app.get("/auth/order-list", async (req, res) => {
  const data = await adm.getOrders(req.query, req.user);
  res.send(data);
});

app.post("/auth/order-done", async (req, res) => {
  const data = await onOrderLogDone(req._body);
  res.send(data);
});

app.post("/auth/order-fee", async (req, res) => {
  const data = await adm.setOrderFee(req._body);
  res.send(data);
});

// NFC手环
app.get("/auth/nfc-list", async (req, res) => {
  const data = await adm.getNfcList(req.query, req.user);
  res.send(data);
});
app.post("/auth/nfc-edit", async (req, res) => {
  const data = await adm.postNfc(req._body, req.user);
  res.send(data);
});

// 人脸比对
app.all("/auth/compare-face", async (req, res) => {
  const { img1, img2 } = req._body;
  const data = await compareFace(img1, img2);
  res.send(data);
});

module.exports = app;
